package com.buding.fx.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.buding.fx.common.constant.CssStyleInfo;
import com.buding.fx.entity.Menu;
import com.buding.fx.entity.SearchData;
import com.buding.fx.entity.SystemConfigInfo;
import com.buding.fx.service.BaseViewService;
import com.buding.fx.service.CenterPageBuildService;
import com.buding.fx.utils.PageRedirectUtils;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;


/**
 * @author mingdongwei-jwk
 * @date 2022/09/15 10:59
 * @class com.buding.fx.service
 * @Description
 */

public class CenterBuildService implements BaseViewService {
    Logger logger  = LoggerFactory.getLogger(CenterBuildService.class);

    @Override
    public Node show(SystemConfigInfo config) {
        CssStyleInfo css = config.getCss();
        VBox vBox = new VBox();
        vBox.setPrefWidth(css.getCenter_weight());
        vBox.setPrefHeight(css.getCenter_height());
        vBox.setStyle("-fx-background-color: white");
        vBox.setMaxHeight(css.getCenter_height());

        logger.info("center node width: "+vBox.getPrefWidth()+"; center node height: "+vBox.getPrefHeight());
        return vBox;
    }

    @Override
    public Node onclickShow(Node onClickNode, SystemConfigInfo configInfo) {
        return show(configInfo);
    }

    public Node selectShow(Menu menu, SystemConfigInfo systemConfigInfo){
        /**
         * 中间区域构建流程：
         * 1.根据menu的redirect判断是否需要展示右边
         * 2.根据redirect获取具体的页面构造器，如果没有就用默认的构建器；如果有就调用各自的构造器创建上中下三部分
         * */
        CssStyleInfo cssStyleInfo = systemConfigInfo.getCss();
        VBox vBox = (VBox) show(systemConfigInfo);
        //获取实际的跳转页面构造器
        CenterPageBuildService centerPageBuildService = PageRedirectUtils.getCenterBuilder(menu.getRedirectUrl());
        AbsPageBuildService centerBuilderService = new AbsPageBuildService(menu, systemConfigInfo,centerPageBuildService);
        Node titleNode = centerBuilderService.buildTopNode();
        if (titleNode!=null){
            vBox.getChildren().add(titleNode);
            VBox.setMargin(titleNode,new Insets(0,0,0,cssStyleInfo.getCenter_content_left()));
        }
        Node searchNode = centerBuilderService.buildSearchNode();
        if (searchNode!=null){
            vBox.getChildren().add(searchNode);
            VBox.setMargin(searchNode,new Insets(5,0,0,cssStyleInfo.getCenter_content_left()));
        }
        Node searchResult = centerBuilderService.bulidSerchResultNode();
        if (searchResult!=null){
            vBox.getChildren().add(searchResult);
            VBox.setMargin(searchResult,new Insets(5,0,0,cssStyleInfo.getCenter_content_left()));
        }
        return vBox;
    }

}
